/**
 * @FilePath     : /14_imx6uirq/imx6uirqAPP.c
 * @Description  :  imx6uirq驱动测试文件
 * @Author       : wxy 173055256627@163.com
 * @Version      : 0.0.1
 * @LastEditors  : wxy 173055256627@163.com
 * @LastEditTime : 2024-12-15 18:52:44
 * @Copyright    : G AUTOMOBILE RESEARCH INSTITUTE CO.,LTD Copyright (c) 2024.
 **/
#include "stdio.h"
#include "unistd.h"
#include "sys/types.h"
#include "sys/stat.h"
#include "fcntl.h"
#include "stdlib.h"
#include "string.h"
#include "sys/ioctl.h"
/*
*argc :应用程序参数
*argv[] :具体的参数内容,字符串形似
  ./imx6uirqAPP <filename>
 ./imx6uirqAPP /dev/imx6uirq 0 表示关灯

*/
#define KEY0VALUE 0XF0 /* 按键值 		*/
#define INVAKEY 0X00   /* 无效的按键值  */

#define CLOSE_CMD _IO(0xEF, 1)     // 关闭命令
#define OPEN_CMD _IO(0xEF, 2)      // 打开命令
#define SETPERIOD_CMD _IO(0xEF, 3) // 设置周期

int main(int argc, char *argv[])
{
    int fd, ret;
    char *filename;
    unsigned char data;
    filename = argv[1];

    if (argc != 2)
    {
        printf("ERROR usage!\r\n");
        return -1;
    }
    /* O_RDWR:读写打开,阻塞方式 */
    fd = open(filename, O_RDWR);
    // fd = open(filename, O_RDWR | O_NONBLOCK);

    if (fd < 0)
    {
        printf("file %s is open fail\r\n", filename);
        return -1;
    }
    else
    {
        printf("file %s is successful!!!\r\n", filename);
    }

    while (1)
    {

        ret = read(fd, &data, 1);
        if (ret < 0)
        {
            /* code */
        }
        else
        {
            if (data)
            {
                printf("data is %#x\r\n", data);
            }
        }
    }
}
